<template>
  <!-- 添加或修改单证业务类型对话框 -->
  <el-dialog :title="title" :visible.sync="dialogVisible" width="1000px" append-to-body :close-on-click-modal="false"
    @close="close">
    <el-form ref="form" :model="form" :rules="rules" label-width="98px" label-position="right" class="flex-form"
      size="small">
      <el-form-item label="业务代码" prop="businessType">
        <el-select v-model.trim="form.businessType" disabled placeholder="请选择业务代码">
          <el-option v-for="dict in dict.type.sys_bill_business_type"  :key="dict.value" :label="dict.label"
            :value="dict.value"></el-option>
        </el-select>
      </el-form-item>

      <el-form-item label="业务名称" prop="businessName">
        <el-input v-model.trim="form.businessName" disabled placeholder="请输入业务名称" />
      </el-form-item>

      <el-form-item label="进出口" prop="iEFlag">
        <el-select v-model.trim="form.iEFlag" disabled placeholder="请选择进出口">
          <el-option v-for="dict in dict.type.sys_i_e_flag"  :key="dict.value" :label="dict.label"
            :value="dict.value"></el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="通关代码" prop="customsStateCode">
        <el-select v-model.trim="form.customsStateCode"  filterable placeholder="请选择通关代码">
          <el-option v-for="dict in dict.type.mft_biz_mode"  :key="dict.value" :label="dict.value+'-'+dict.label"
            :value="dict.value"></el-option>
        </el-select>
      </el-form-item>

      <el-form-item label="运输方式" prop="trafMode">
        <el-select v-model.trim="form.trafMode" disabled placeholder="请选择运输方式">
          <el-option v-for="dict in dict.type.sys_filed_type" :key="dict.value" :label="dict.label"
            :value="dict.value"></el-option>
        </el-select>
      </el-form-item>

      <el-form-item label="贸易类型" prop="tradeType">
        <el-select v-model.trim="form.tradeType" placeholder="请选择贸易类型">
          <el-option v-for="dict in dict.type.trade_type_list" :key="dict.value" :label="dict.label"
            :value="dict.value"></el-option>
        </el-select>
      </el-form-item>

      <el-form-item label="单证类型" prop="billType">
        <el-select v-model.trim="form.billType" placeholder="请选择单证类型">
          <el-option v-for="dict in dict.type.bill_type_list" :key="dict.value" :label="dict.label"
            :value="dict.value"></el-option>
        </el-select>
      </el-form-item>

      <el-form-item label="单证分类" prop="billCategory">
        <el-select v-model.trim="form.billCategory" placeholder="请选择单证分类">
          <el-option v-for="dict in dict.type.business_type_category" :key="dict.value" :label="dict.label"
            :value="dict.value"></el-option>
        </el-select>
      </el-form-item>



    </el-form>
    <div slot="footer" class="dialog-footer">
      <el-button type="primary" @click="submitForm">确 定</el-button>
      <el-button @click="close">取 消</el-button>
    </div>
  </el-dialog>
</template>

<script>
  import {
    getBillBusinessType,
    addBillBusinessType,
    updateBillBusinessType
  } from "@/api/billsdecl/billBusinessType";
  export default {
    name: "BillBusinessType-addEdit",
    props: {
      dialogType: {
        type: String,
        default: "add",
      },
      rowData: {
        type: Object,
        default: () => {},
      },
      dict: {}
    },
    data() {
      return {
        // 弹出层
        dialogVisible: false,
        // 标题
        title: "新增",
        // 表单参数
        form: {
          id: null,
          businessType: null,
          businessName: null,
          iEFlag: null,
          tradeType: null,
          billType: null,
          billCategory: null,
          trafMode: null,
          createBy: null,
          createTime: null,
          updateTime: null,
          updateBy: null,
          customsStateCode:null

        },
        // 单证业务类型表格数据
        billBusinessTypeList: [],
        // 表单校验
        rules: {
          businessType: [{
            required: true,
            message: "业务代码不能为空",
            trigger: "change"
          }],
          businessName: [{
            required: true,
            message: "业务名称不能为空",
            trigger: "blur"
          }],
          iEFlag: [{
            required: true,
            message: "进出口不能为空",
            trigger: "change"
          }],
          tradeType: [{
            required: true,
            message: "贸易类型不能为空",
            trigger: "change"
          }],
          billCategory: [{
            required: true,
            message: "单证分类不能为空",
            trigger: "change"
          }],
          trafMode: [{
            required: true,
            message: "运输方式不能为空",
            trigger: "change"
          }],
        }
      };
    },
    methods: {
      open() {
        this.dialogVisible = true;
        this.$nextTick(() => {
          if (this.dialogType == "add") {
            this.title = "新增";
          } else if (this.dialogType == "edit") {
            this.title = "编辑";
            this.loadDetail();
          } else if (this.dialogType == "detail") {
            this.title = "详情";
            this.loadDetail();
          }
        });
      },
      close() {
        this.$refs["form"].resetFields();
        this.dialogVisible = false;
      },

      // 获取详情
      loadDetail() {
        const id = this.rowData.id;
        getBillBusinessType(id).then((res) => {
          if (res.code == 200) {
            this.form = res.data;
          }
        });
      },

      // 提交表单
      submitForm() {
        this.$refs["form"].validate(valid => {
          if (valid) {
            let params = {
              ...this.form,
            };
            if (this.dialogType == "add") {
              addBillBusinessType(this.form).then(res => {
                if (res.code === 200) {
                  this.$modal.msgSuccess("新增成功");
                  this.close();
                  this.$emit("handleQuery");
                }
              });
            } else {
              params.id = this.rowData.id;
              updateBillBusinessType(this.form).then(res => {
                if (res.code === 200) {
                  this.$modal.msgSuccess("修改成功");
                  this.close();
                  this.$emit("handleQuery");
                }
              });
            }
          }
        });
      },
    },
  };
</script>

<style lang="scss" scoped></style>
